package cn.itcast.service.impl;

import cn.itcast.mapper.DeptMapper;
import cn.itcast.pojo.Dept;
import cn.itcast.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service

public class DeptServiceImpl implements DeptService {
    @Autowired
    private DeptMapper deptMapper;


    @Override
    public List<Dept> findAll() {
        List<Dept> list = deptMapper.findAll();
        return list;
    }

    @Override
    public boolean deleteById(int id) {
      int row = deptMapper.deleteById(id);
      return row > 0;
    }

    //添加部门
    @Override
    public boolean add(Dept dept) {
        //补全数据
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());

        int result = deptMapper.add(dept);
        return result > 0;
    }

    @Override
    public Dept findById(int id) {
        Dept dept = deptMapper.findById(id);

        return dept;
    }

    @Override
    public boolean update(Dept dept) {
        dept.setUpdateTime(LocalDateTime.now());
       int row = deptMapper.update(dept);
        return row > 0;
    }


}
